<?php
namespace Admin\Controller;
use Think\Controller;

class NewsaddController extends Controller {
    public function index(){
      
        $this->display();
    }

    public function add(){
    	$data = I('post.');
    	$data['create_time']=time();
    	//var_dump($data);exit;
    	$res = M('news')->add($data);
    	if($res){
    		$this->ajaxReturn(['error'=>0,'info'=>'添加成功']);
    	}else{
    		$this->ajaxReturn(['error'=>1,'info'=>'添加失败']);
    	}
    }

    public function upload(){
		//var_dump($_FILES);
		$upload = new \Think\Upload();// 实例化上传类
	    $upload->maxSize   =     3145728 ;// 设置附件上传大小
	    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
	    $upload->rootPath  =     './Uploads/pic/admin'; // 设置附件上传根目录
	    $upload->savePath  =     ''; // 设置附件上传（子）目录
	    // 上传文件 
	    $info   =   $upload->upload();
	    if(!$info) {// 上传错误提示错误信息
	        //$this->error($upload->getError());
	        echo "失败";
	    }else{// 上传成功
	        $pic = __ROOT__.'/Uploads/pic/admin'.$info['file']['savepath'].$info['file']['savename'];

	        $arr=array(
	        	"code"=> 0,
	        	"msg"=> '成功',
	        	'data'=>array(
	        		'src'=>$pic,
	        		'title'=>'图片'
	        	)
	        );

	        echo json_encode($arr);
	    }
	}
}

?>